<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <title>检查密码短语中的字母和数字字符</title>
</head>
<body>
<script>
    var input = prompt('Please enter a pass phrease.', '');
    function isValid(text) {
        var myRegExp = /[^a-z\d ]/i;
        return !myRegExp.test(text);
    }
    if (isValid(input)) {
        alert('Your passphrase contains only valid characters');
    } else {
        alert('Your passphrase contains one or more invalid characters');
    }

    function isValid2(text) {
        var returnValue = true;
        var validChars = 'abcdefghijklmnopqrstuvwxyz1234567890 ';
        for (var i = 0; i < text.length; i++) {
            if (validChars.indexOf(text.charAt(i).toLowerCase()) < 0) {
                returnValue = false;
                break;
            }
        }
        return returnValue;
    }
</script>
</body>
</html>